/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop  aa *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA              *
 ***************************************************************************/
#include "aminoacid.h"
namespace bol{


double *AminoAcid::s_char2mass = NULL;
#ifdef _MSC_VER // MSVC has strange static const
const unsigned char AminoAcid::CHAR_NTERM_PEPTIDE=27;
const unsigned char AminoAcid::CHAR_CTERM_PEPTIDE=28;
#endif


void AminoAcid::initChar2mass(){

  if (s_char2mass)
    return;
  s_char2mass=new double[256];
  for(int i=0; i<256; i++){
    s_char2mass[i]=0.;
  }
}


unsigned char AminoAcid::aa2reduced(const unsigned char AA){
  if(AA=='^'){
    return 27;
  }else if(AA=='$'){
    return 28;
  }else{
    assert((AA >='A') && (AA <='Z'));
    return 1+AA-'A';
  }
}
    

unsigned char AminoAcid::reduced2aa(const unsigned char c){
  switch( c ){
  case 27:
    return '^';
  case 28:
    return '$';
  case 0:
    return 0;
  default:
    return 'A'+c-1;
  }
}


} // namespace bol
